<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>offset</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .father {
            /* position: relative; */
            width: 200px;
            height: 180px;
            background-color: skyblue;
            border: 2px solid red;
            padding: 5px;
            margin: 150px;
        }

        .son {
            width: 100px;
            height: 100px;
            background-color: purple;
            margin-left: 45px;
        }

        .janna {
            /* width: 300px; */
            height: 200px;
            background-color: skyblue;
            margin: 0 auto 200px;
            padding: 10px;
            border: 15px solid red;
        }
    </style>
</head>
<body>
    <div class="father">
        father    <!-- <h3>123</h3> -->
        <div class="son">son</div>
    </div>
    <div class="janna">娜迦</div>
    <script>
        /* 
            轮播图的移动：当前距离 + 若干像素，重新赋值

            offset  抵消  弥补   补偿
            1. offsetLeft : 元素左侧的偏移量
            2. offsetTop: 元素上侧的偏移量
            3. offsetLeft、offsetTop 是以父级为参考物。父级必须有定位，否则就是以 body 为参考系
            4. 没有 右侧和下侧的偏移量
            5. offsetWidth = width + border + padding
            6. offsetHeight = height + border + padding
            7. offsetWidth 可以动态地获取元素的尺寸
            8. offsetParent 获取有父级定位的元素节点 
        */
       let father = document.querySelector('.father');
       let son = document.querySelector('.son');

       console.log(father.offsetLeft);  //  150
       console.log(father.offsetTop);   //  150

       console.log(son.offsetLeft);  //  50
       console.log(son.offsetTop);  //  26   文字的高度＋内边距  

       console.log(father.offsetWidth);  //214
       console.log(father.offsetHeight);  //194

       console.log(son.parentNode);
       console.log(son.offsetParent);  
       //  如果父级没有定位，offsetParent就是获取的整个body的节点
       //  parentNode 获取father里的全部节点 
       //  如果父级有定位.两者获取的都是父级里的节点
    </script>
</body>
</html>